enum valtype
{
	speed,
	alpha,
	move
}
enum movetype
{
	stight,
	sin,
	cos,
	tan,
	log,
	ex
}
class CAnimation {
	

    //开关
    firstime:boolean=true
	end:boolean=false
	//最终消息
	endcall:boolean=false
    
	//对象信息
	ptr:CBASE
	fun:string
	tox:number
	toy:number
	usetime:number
	speed:number
	val:valtype
	move:movetype
	//向量
	vectox:number
	vectoy:number
	vectoline:number
	//速度
	speedx:number
	speedy:number





	public constructor(pic:CBASE,x?:number,y?:number,time?:number,fun?:string) {
		if(time==undefined)
		{
			this.usetime=1000
		}
		else{
			this.usetime=time
		}
		if(fun!=undefined)
		{
			this.endcall=true
			//console.log("1234")
			
			this.fun=fun;
		}
		else{
			//this.ptr=ptr;
			//this.fun=fun;
			this.endcall=false;
		}
		this.tox=x;
		this.toy=y;
		this.ptr=pic;
	}
    public to(point:egret.Point|number,time?:number,valtype?:valtype,movetype?:movetype)
	{
      
	}
	private setvector_StraightLine(x?:number,y?:number,time?:number,fun?:string)
	{
		if(this.firstime)
	    {
		   if(time!=undefined)
		   {
			   this.usetime=time;
		   }
	
		   if(fun!=undefined)
		   {
			   this.endcall=true;
			  
			   this.fun=fun;
		   }
	
		   if(x!=undefined||y!=undefined)
		   {
			   console.log("???")
			   if(x==undefined)
			   {
                   this.tox=0;
			       this.toy=y;
			   }
			   else if(y==undefined)
			   {
                   this.tox=x;
			       this.toy=0;
			   }
			   else
			   {
                   this.tox=x;
			       this.toy=y;
			   }
			  
		   }
		
		 
		   this.vectox=this.tox-(this.ptr.x)
		   this.vectoy=this.toy-(this.ptr.y)
		   //console.log(this.vectox,this.vectoy,this.vectox/100)
		   this.vectoline=Math.sqrt((this.tox*this.tox)+(this.toy*this.toy))
		   //获得单位向量
		   this.vectox=this.vectox/this.vectoline
		   this.vectoy=this.vectoy/this.vectoline
           //console.log(this.vectox,this.vectoy,this.vectoline)
            
		   //对应时间
		   var frame=/*egret.MainContext.instance.stage.frameRate*/0 //获得帧数
		   var usetime_S=this.usetime/1000 //转换为秒
		   var framenumber=frame*usetime_S//获得总帧数

		   this.speed=this.vectoline/framenumber  //向量线段长度除以总帧数，获得速度

            //注册事件
		    this.ptr.addEventListener(egret.Event.ENTER_FRAME,this.setvector_StraightLine,this);
			this.firstime=false;
		
	    }
		else
		{
			  //连点失败
			return this.StraightLineupdate();
		}


	}
	private StraightLineupdate()
	{
	   if(this.end)
	   {
		   return this;
	   }
       else if(this.ptr.x==this.tox&&this.ptr.y==this.toy)
	   {
           this.callend()
		   this.end=true;
	   }
	   else
	   {
          this.ptr.x+=this.speed*this.vectox
		  this.ptr.y+=this.speed*this.vectoy
          
          
		  //判断是否抵达终点
		  var x:number=this.tox-(this.ptr.x)
		  var y:number=this.toy-(this.ptr.y)
		  var line:number=(x*x)+(y*y)
		 //console.log(this.parentx,this.parenty)
		  //console.log(x,y)
		  //console.log(line,this.speed)
		  if(line<=this.speed*this.speed)
		  {
			  this.ptr.x=this.tox;
			  this.ptr.y=this.toy;
		  }
		
	   }
	}
	private callend()
	{
        this.ptr.removeEventListener(egret.Event.ENTER_FRAME,this.setvector_StraightLine,this);
	   	if(this.endcall)
		{
			this.ptr[this.fun]
		}
	    else
		{
		   this.ptr.sendevent("animeend");
		}
	}
}